package com.jh3502.vivo.function.messagedetail;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jh3502.vivo.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * author:harisucici on 2018/11/14 11:33
 * email:harisucici@gmail.com
 * name:
 * todo:
 */
public class MessageDetailSysAdapter extends RecyclerView.Adapter<MessageDetailSysAdapter.ViewHolder> implements View.OnClickListener {
    Context mContext;

    private View convertView;
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;
    private List<String> dataList = new ArrayList<>(2);

    public MessageDetailSysAdapter(Context context) {
        this.mContext = context;

    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        convertView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_sys_msg, viewGroup, false);
        ViewHolder vh = new ViewHolder(convertView);
        convertView.setOnClickListener(this);
        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, final int position) {
        viewHolder.itemView.setTag(position);
        viewHolder.itemMsgCont.setText(dataList.get(position));


    }

    @Override
    public void onClick(View v) {
        if (mOnItemClickListener != null) {

            mOnItemClickListener.onItemClick((int) v.getTag());
        }
    }


    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    public void setData(List<String> dataList) {
        this.dataList = dataList;
    }

    public interface OnRecyclerViewItemClickListener {
        void onItemClick(int i);
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_msg_date)
        TextView itemMsgDate;
        @BindView(R.id.item_msg_cont)
        TextView itemMsgCont;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);

        }
    }

}
